package com.huadi.firematerialident.dao;

import com.huadi.firematerialident.po.NormalUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

@Repository
public class NormalUserDaoImpl implements NormalUserDao{

    @Autowired
    JdbcTemplate jdbcTemplate;

    public int addNormalUser(NormalUser NormalUser) {
        String sql="insert into NormalUser values(?,?,?,?,?,?,?,1,now())";
        System.out.println("插入了数据");
        return jdbcTemplate.update(sql,
                NormalUser.getNUserID(),
                NormalUser.getNUserCount(),
                NormalUser.getNPassword(),
                NormalUser.getNName(),
                NormalUser.getNSex(),
                NormalUser.getNBirth(),
                NormalUser.getNPhone());
    }
    public int deleteNormalUserByID(String NUserID) {
        String sql="update NormalUser set LogicalAddDel=0,LastModification=now() where NUserID=?";
        return jdbcTemplate.update(sql,NUserID);
    }


    public int updateNormalUser(NormalUser normalUser) {
        String sql="update NormalUser set NUserID=?,NUserCount=?,NPassword=?," +
                "NName=?,NSex=?,NBirth=?,NPhone=?,LastModification=now() where NUserID=?";
        return jdbcTemplate.update(sql,normalUser.getNUserID(),
                normalUser.getNUserCount(),
                normalUser.getNPassword(),
                normalUser.getNName(),
                normalUser.getNSex(),
                normalUser.getNBirth(),
                normalUser.getNPhone(),normalUser.getNUserID());
    }


    public List<Map<String,Object>> selectNormalUserByID(String NUserID) {
        String sql = "select * from normalUser where NUserID = ?";
        return jdbcTemplate.queryForList(sql,NUserID);
    }



    public List<Map<String,Object>> getAllNormalUser() {
        String sql="select * from normalUser";
        return jdbcTemplate.queryForList(sql);
    }

}
